New Project

  • Steps

    Step 1:
    Open Android Studio

    Step 2:
    Select Flutter New Project option

    Step 3:
    Clear lib/main.dart and add followings

    Using Simple code
    
                            import 'package:flutter/material.dart';
        
                            // the main() function is the starting point for every Flutter project
                            void main() {
                            
                              // calling this method (you guessed it) runs our app
                              runApp(
                              
                                Container(
                                  color: Colors.green, // <-- change this
                                ),
                                
                              );
                            }
    
                           
    Using class
    
    
                            import 'package:flutter/material.dart';
    
                            void main() {
                              runApp(const MyApp());
                            }
                            
                            class MyApp extends StatelessWidget {
                              const MyApp({Key? key}) : super(key: key);
                              @override
                              Widget build(BuildContext context) {
                                return const MaterialApp(
                                  home: Text("Hello World Niluka"),
                                );
                              }
                            }
    
                            
    App bar & body
    We must use 'Scaffold layout' for creating page tree
    
    
                            import 'package:flutter/material.dart';
    
                            void main() {
                              runApp(const MyApp());
                            }
    
                            class MyApp extends StatelessWidget {
                              const MyApp({Key? key}) : super(key: key);
    
                              @override
                              Widget build(BuildContext context) {
                                return MaterialApp(
                                  title: 'Welcome to Flutter',
                                  home: Scaffold(
                                    appBar: AppBar(
                                      title: const Text('Welcome to Flutter'),
                                    ),
                                    body: const Center(
                                      child: Text('Hello World'),
                                    ),
                                  ),
                                );
                              }
                            }
    
                          
    1) appBar inside home
    2) body inside home

    Examples

    Change home property of 'MaterialApp'

    Container
    
                          home: Scaffold(
                            body: Container(
                              color: Colors.blue,
                              child: Center(
                                child: Text('Hello, Flutter!'),
                              ),
                            ),
                          )
                          
    Column
    
                          Scaffold(
                              body: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text('Item 1'),
                                  Text('Item 2'),
                                  Text('Item 3'),
                                ],
                              ),
                            )
    
                            
    Row
    
                            Scaffold(
                                body: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text('Item 1'),
                                    Text('Item 2'),
                                    Text('Item 3'),
                                  ],
                                ),
                              )
    
                              
    ListView
    
                              Scaffold(
                                  body: ListView(
                                    children: [
                                      ListTile(title: Text('Item 1')),
                                      ListTile(title: Text('Item 2')),
                                      ListTile(title: Text('Item 3')),
                                    ],
                                  ),
                                )
                                
    Expanded
    
    
                                Scaffold(
                                  body: Column(
                                    children: [
                                      Text('Fixed Height Widget'),
                                      Expanded(
                                        child: Container(
                                          color: Colors.blue,
                                        ),
                                      ),
                                    ],
                                  ),
                                )
    
                                
    Stack
    
                                Scaffold(
                                  body: Stack(
                                    children: [
                                      Positioned(
                                        top: 50,
                                        left: 50,
                                        child: Text('Overlay Text'),
                                      ),
                                      Center(
                                        child: Image.asset('assets/image.png'),
                                      ),
                                    ],
                                  ),
                                )